package NewCoder;

import java.util.ArrayList;
import java.util.List;

public class BM23 {
    public void pre(List<Integer> list, TreeNode root){
        if(root==null) return;
        list.add(root.val);
        pre(list,root.left);
        pre(list,root.right);

    }
    public int[] preorderTraversal (TreeNode root) {
        // write code here
        List<Integer> list=new ArrayList<>();
        pre(list,root);
        int[] arr=new int[list.size()];
        for(int i=0;i<arr.length;i++){
            arr[i]=list.get(i);
        }
        return arr;
    }
}
